package com.xintai.sparepart.purchase.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.sparepart.purchase.domain.BeiPurchase;
import com.xintai.sparepart.purchase.service.IBeiPurchaseService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 采购申请主Controller
 *
 * @author xintai
 * @date 2021-02-20
 */
@RestController
@RequestMapping("/beijiancailiao/apply/purchase")
public class BeiPurchaseController extends BaseController
{
    @Autowired
    private IBeiPurchaseService beiPurchaseService;

    /**
     * 查询采购申请主列表
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:purchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(BeiPurchase beiPurchase)
    {
        startPage();
        List<BeiPurchase> list = beiPurchaseService.selectBeiPurchaseList(beiPurchase);
        return getDataTable(list);
    }

    /**
     * 导出采购申请主列表
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:purchase:export')")
    @Log(title = "采购申请主", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BeiPurchase beiPurchase)
    {
        List<BeiPurchase> list = beiPurchaseService.selectBeiPurchaseList(beiPurchase);
        ExcelUtil<BeiPurchase> util = new ExcelUtil<BeiPurchase>(BeiPurchase.class);
        return util.exportExcel(list, "purchase");
    }

    /**
     * 获取采购申请主详细信息
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:purchase:query')")
    @GetMapping(value = "/{beiId}")
    public AjaxResult getInfo(@PathVariable("beiId") Long beiId)
    {
        return AjaxResult.success(beiPurchaseService.selectBeiPurchaseById(beiId));
    }

    /**
     * 新增采购申请主
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:purchase:add')")
    @Log(title = "采购申请主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BeiPurchase beiPurchase)
    {
        return toAjax(beiPurchaseService.insertBeiPurchase(beiPurchase));
    }

    /**
     * 修改采购申请主
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:purchase:edit')")
    @Log(title = "采购申请主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BeiPurchase beiPurchase)
    {
        return toAjax(beiPurchaseService.updateBeiPurchase(beiPurchase));
    }

    /**
     * 删除采购申请主
     */
    @PreAuthorize("@ss.hasPermi('beijiancailiao:purchase:remove')")
    @Log(title = "采购申请主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{beiIds}")
    public AjaxResult remove(@PathVariable Long[] beiIds)
    {
        return toAjax(beiPurchaseService.deleteBeiPurchaseByIds(beiIds));
    }
}
